<template lang="pug">
dialogModel(
    ref="dialogLoad"
    :title="title"
    width="880"
    :footer="false"
)
    .cont-wrap
        .search-w
            searchModel(:searchList="searchList" @searchSubmit="searchSubmit" @searchReset="searchReset()")
                template(#searchSlot)
                    el-button(type="primary" @click="clearRecord()" style="margin-left: 190px" link) 清空{{title=='下载记录'?'下载':'浏览'}}记录
        .table-w
            tableModel(
                ref="tableRef"
                :data="tableData"
                :pagination="false"
            )
                el-table-column(prop="fileName" label="文件名称" align="center" width="400" show-overflow-tooltip)
                el-table-column(prop="createDate" label="下载时间" align="center" show-overflow-tooltip v-if="title=='下载记录'")
                el-table-column(prop="createDate" label="浏览时间" align="center" show-overflow-tooltip v-else)
</template>

<script setup>
import searchModel from '@/components/searchModel.vue'
import { ref, onMounted } from 'vue'
import tableModel from '@/components/tableModel.vue'
import dialogModel from '@/components/dialogModel.vue'
import apis from '@/apis'
import { success, confirm } from '@/utils/message'

const title = ref('下载记录')
const dialogLoad = ref(null)
const open = (type) =>{
    title.value = type
    dialogLoad.value.open()
    cyFilequeryRecord()
}

//文件列表
const searchList = [
    { type: 'input', label: '文件名称', maxlength: 50, prop: 'fileName' }
]

let results = {}
const searchSubmit = result => {
    results = result
    cyFilequeryRecord()
}
const searchReset = () => {
    results = {}
    cyFilequeryRecord()
}
//列表
const tableData = ref([])
const cyFilequeryRecord = () => {
    tableData.value = []
    apis.cyFilequeryRecord({
        ...results,
        type: title.value == '下载记录' ? 1 : 2
    }).then(res => {
        if(res.status == 1){
            tableData.value = res.data
        }
    })
}
//清空记录
const clearRecord = () => {
    if(tableData.value.length == 0){
        return
    }
    confirm(`确定清空${title.value == '下载记录' ? '下载' : '浏览'}记录吗？`, ()=>{
        apis.clearRecord({
            type: title.value == '下载记录' ? 1 : 2
        }).then(res => {
            if(res.status == 1){
                success(res.msg)
                cyFilequeryRecord()
            }
        })
    })
}
defineExpose({
    open
})

</script>

<style lang="less" scoped>
:deep(.el-menu-item){
    line-height: 40px;
}
.cont-wrap{
    margin-top:20px;
    height: 420px;
    border-bottom: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    .table-w{
        flex-grow: 1;
        overflow: hidden;
    }
}
.label{
    line-height: 30px;
    text-align: right;
}
:deep(.el-row){
    margin-bottom: 20px;
}
:deep(.search-box.roleCodes){
    .input-box{
        width: 100%;
    }
}
</style>